package com.mlj.controller;

import com.mlj.pojo.Apartment;
import com.mlj.service.ApartmentService;
import com.mlj.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/apartment")
public class ApartmentController {
    @Autowired
    private ApartmentService apartmentService;
    /**
     * 公寓列表页面
     */
    @RequestMapping("/apartmentlist_page")
    public String apartmentListPage(){
        return "apartmentlist";
    }
    /**
     * 公寓信息添加页面
     */
    @RequestMapping("/addapartment_page")
    public String addApartmentPage(){
        return "addapartment";
    }
    /**
     * 查询公寓名称
     */
    @RequestMapping("/getApartmentName")
    @ResponseBody
    public List<Apartment> selectApartmentName(){
        return  apartmentService.selectApartmentName();
    }
    /**
     *
     * 分页查询列表
     */
    @RequestMapping("/apartmentlist")
    @ResponseBody// json格式数据
    public Result apartmentList(Integer page, Integer limit){
        return apartmentService.getApartmentList(page,limit);
    }
    /**
     * 根据id删除
     */
    @RequestMapping("/delApartmentById")
    @ResponseBody
    public Result delApartmentById(Integer id){
        return apartmentService.delApartmentById(id);
    }
    /**
     * 批量删除
     */
    @RequestMapping("/deleteBatch")
    @ResponseBody
    public Result deleteBatch(Integer [] ids){
        return apartmentService.deleteBatch(ids);
    }
    /**
     * 添加公寓信息
     */
    @RequestMapping("/addapartment")
    @ResponseBody
    public Result addApartment(Apartment apartment){
        return  apartmentService.addApartment(apartment);
    }
    /**
     * 修改公寓信息
     */
    @RequestMapping("/updateapartment")
    @ResponseBody
    public Result updateApartment(Apartment apartment){
        return  apartmentService.updateApartment(apartment);
    }
    /**
     *条件模糊查询
     */
    @RequestMapping("/search")
    @ResponseBody
    public Result search(String address,Integer page,Integer limit){
        return apartmentService.search(address,page,limit);
    }
}
